//
//  LSAnalyzeCell.m
//  LookScore
//
//  Created by wr on 2018/3/22.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSAnalyzeCell.h"
#import "LSAnalyzeRecentNestedCell.h"
#import "LSAnalysisModel.h"
#import "LSMarchDetailModel.h"
#pragma mark 🔥 LSAnalyzeCell
@interface LSAnalyzeCell()
@property (nonatomic, strong) NSMutableArray * labelArray;
@end

@implementation LSAnalyzeCell
- (NSMutableArray *)labelArray{
    if (!_labelArray) {
        _labelArray = @[].mutableCopy;
    }
    return _labelArray;
}
+(LSAnalyzeCell *)AnalyzeCellByTableView:(UITableView *)tableView{
    LSAnalyzeCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSAnalyzeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    
    return self;
}

- (void)setModel:(AnalysisHistoricalArrayList *)model{
    
    _model = model;
    NSString * timeStr = [model.MatchTime componentsSeparatedByString:@" "].firstObject;
    NSArray * array = @[[NSString stringWithFormat:@"%@\n%@",model.LeagueName,timeStr],[NSString stringWithFormat:@"%@ %@ %@",model.HomeTeamName,model.QScore,model.GuestTeamName],[NSString stringWithFormat:@"%@%@",model.PanLu,model.Result]];
    
    [self.labelArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UILabel * label = (UILabel *)obj;
        
        label.text = array[idx];
    }];
    
}

-(void)addContentView{
    NSArray *titleArray = @[@"世界联赛17-09-10",@"莫斯科火车头 2-2 莫斯科火车头",@"0.5/1输"];
    
    CGFloat width=(LSScreenWidth - 20)/3;
    UILabel *lable;
    for (int i=0; i<3; i++) {
        lable=[UILabel new];
        lable.text = titleArray[i];
        lable.textColor = LSTitleGrayColor3;
        lable.font=LSFontSize(12, LSScreenWidth);
        lable.tag=i;
        [self.contentView addSubview:lable];
        [self.labelArray addObject:lable];
        lable.sd_layout.leftEqualToView(self.contentView).offset(width*i + 10).topEqualToView(self.contentView).centerYEqualToView(self.contentView).widthIs(width).heightIs(30);
        if (i == 0) {
            lable.textAlignment = NSTextAlignmentLeft;
            lable.numberOfLines = 2;
            lable.sd_layout.widthIs(80);
        }
        else if (i == 1){
            lable.textAlignment = NSTextAlignmentCenter;
            lable.sd_layout.leftEqualToView(self.contentView).offset(80).widthIs(200);
        }
        else{
            lable.textAlignment = NSTextAlignmentRight;
            lable.sd_layout.rightEqualToView(self.contentView).offset(-10).widthIs(80);
        }
    }
}
@end


#pragma mark 🔥 LSAnalyzeRecentCell
@interface LSAnalyzeRecentCell()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *cellTableView;




@end

@implementation LSAnalyzeRecentCell
//- (NSMutableArray *)dataArray{
//    if (!_dataArray) {
//        _dataArray = @[].mutableCopy;
//    }
//    return _dataArray;
//}
+(LSAnalyzeRecentCell *)AnalyzeRecentCellByTableView:(UITableView *)tableView{
    LSAnalyzeRecentCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSAnalyzeRecentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    
    return self;
}

-(void)addContentView{
    
    self.cellTableView.estimatedSectionHeaderHeight = 0;
    self.cellTableView.estimatedSectionFooterHeight = 0;
    [self.contentView addSubview:self.cellTableView];
    
    self.cellTableView.sd_layout
    .leftEqualToView(self.contentView)
    .topEqualToView(self.contentView)
    .rightEqualToView(self.contentView);
    
    
    
}
//更新控件的位置
- (void)layoutSubviews {
    
    
}

#pragma mark -- Getter / Setter

- (UITableView *)cellTableView
{
    if (!_cellTableView) {
        _cellTableView = [[UITableView alloc]init];
       
        _cellTableView.backgroundColor =LSBackGroundColor;
        _cellTableView.showsVerticalScrollIndicator = NO;
        _cellTableView.scrollEnabled = NO;
        _cellTableView.delegate = self;
        _cellTableView.dataSource = self;
        _cellTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
       
    }
    return _cellTableView;
}

- (void)setDataArray:(NSMutableArray *)dataArray{
    _dataArray = dataArray;
   
}

- (void)setModel:(recentRecord *)model{
    _model = model;
    float H = model.teamArray.count * 30.00;
    float tableH;
    if (model.isSeeMoreHidden) {
        
        tableH = H + 60;
    }else{
        
        tableH = H + 87;
    }
    
    self.cellTableView.sd_resetLayout
    .leftEqualToView(self.contentView)
    .topEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .heightIs(tableH);
    
    [self.cellTableView reloadData];
    [self setupAutoHeightWithBottomView:self.cellTableView bottomMargin:0];
    
}

- (void)setMarModel:(LSMarchDetailModel *)marModel{
    _marModel = marModel;
    
}

#pragma mark -- <UITableViewDelegate,UITableViewDataSource>
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.model.teamArray.count;
   
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSAnalyzeRecentNestedCell *cell=[LSAnalyzeRecentNestedCell AnalyzeRecentNestedCellByTableView:tableView];
    cell.model = self.model.teamArray[indexPath.row];
    if (indexPath.row % 2 != 0) {
        cell.backgroundColor = LSSubGrayColorf7;
    }
    else{
        cell.backgroundColor = [UIColor whiteColor];
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 60;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    if (_model.isSeeMoreHidden || self.model.teamArray.count == 0) {
        return 0.01;
    }
    
    return 27;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
//    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.width, 60)];
    UIView * header = [tableView headerViewForSection:section];
    if (!header) {
        
        header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, LSScreenWidth, 60)];
//        header.sd_layout.topSpaceToView(self.contentView, 0).leftEqualToView(self.contentView).offset(0).rightEqualToView(self.contentView).offset(0).bottomEqualToView(self.contentView);
        header.backgroundColor = LSSubGrayColorf7;
        if (self.model.teamArray.count == 0) {
            UILabel * label = [[UILabel alloc] init];
            label.text = @"暂无数据";
            label.textAlignment = NSTextAlignmentCenter;
            [header addSubview:label];
            
            label.sd_layout
            .leftEqualToView(header)
            .rightEqualToView(header)
            .topEqualToView(header)
            .bottomEqualToView(header);
            
        }else{
            
            NSArray *titleArray = @[@"赛事日期",@"比分",@"盘路"];
            CGFloat width=(LSScreenWidth - 20)/3;
            UILabel *lable;
            for (int i=0; i<3; i++) {
                lable=[UILabel new];
                lable.text = titleArray[i];
                lable.textColor = LSTitleGrayColor3;
                lable.font=LSFontSize(12, LSScreenWidth);
                lable.tag=i;
                [header addSubview:lable];
                lable.sd_layout
                .leftEqualToView(header).offset(width*i + 10)
                .topEqualToView(header).offset(30)
                .centerYEqualToView(header)
                .widthIs(width)
                .heightIs(30);
                if (i == 0) {
                    lable.textAlignment = NSTextAlignmentLeft;
                }
                else if (i == 1){
                    lable.textAlignment = NSTextAlignmentCenter;
                }
                else{
                    lable.textAlignment = NSTextAlignmentRight;
                }
            }
            
            UIView *halfWhiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.width, 30)];
            halfWhiteView.backgroundColor = [UIColor whiteColor];
            UILabel * teamNameLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 80, 30)];
            teamNameLab.textColor = LSTitleGrayColor3;
//            teamNameLab.numberOfLines = 2;
            teamNameLab.font = LSFontSize(12, LSScreenWidth);
            UILabel *recordLab = [[UILabel alloc] initWithFrame:CGRectMake(90, 0, self.contentView.width - 50, 30)];
            
            //        teamArray * tModel = self.model.teamArray[section];
            
            if (_myIndexPath.row == 0) {
                teamNameLab.text = self.marModel.HomeTeamName_CN;
                recordLab.text = [NSString stringWithFormat:@"近%@场， 胜%@  平%@  负%@   胜率%@%%   赢盘率%@%%",_matchModel.Home_Number,_matchModel.Home_Win,_matchModel.Home_Flat,_matchModel.Home_Loss,_matchModel.Home_WinProba,_matchModel.Home_WinDiscProba];
            }else{
                teamNameLab.text = self.marModel.GuestTeamName_CN;
                recordLab.text = [NSString stringWithFormat:@"近%@场， 胜%@  平%@  负%@   胜率%@%%   赢盘率%@%%",_matchModel.Guest_Number,_matchModel.Guest_Win,_matchModel.Guest_Flat,_matchModel.Guest_Loss,_matchModel.Guest_WinProba,_matchModel.Guest_WinDiscProba];
            }
            
            //        recordLab.text = @"克拉斯诺达 近5场，胜2 平2 负1 胜率 45% 赢盘率 50%";
            recordLab.textColor = LSTitleGrayColor3;
            recordLab.font = LSFontSize(12, LSScreenWidth);
            
            [halfWhiteView addSubview:teamNameLab];
            [halfWhiteView addSubview:recordLab];
            [header addSubview:halfWhiteView];
        }
        
    }
    return header;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (_model.isSeeMoreHidden || self.model.teamArray.count == 0) {
        return nil;
    }else{
        
        UIView * footer = [tableView footerViewForSection:section];
//        if (!footer) {
            footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.width, 27)];
            footer.backgroundColor = [UIColor clearColor];
            UIButton *checkMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            checkMoreBtn.backgroundColor = [UIColor whiteColor];
            checkMoreBtn.frame = CGRectMake(0, 1, footer.width, 26);
            checkMoreBtn.titleLabel.font = LSFontSize12;
            [checkMoreBtn setTitle:@"显示更多" forState:UIControlStateNormal];
            [checkMoreBtn setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
            [checkMoreBtn addTarget:self action:@selector(action_ClickCheckMoreBtn:) forControlEvents:UIControlEventTouchUpInside];
            [footer addSubview:checkMoreBtn];
            return footer;
//        }else{
        
//            return nil;
//        }
        
        
    }
    
   
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    MyLog(@"233333  %@",self.infoList[indexPath.row][@"sId"]);
//
//    [_delegate clickCell:self.infoList[indexPath.row][@"sId"]];
//    //DailyDetailViewController *ddvc = [[DailyDetailViewController alloc]init];
    
}


- (void)action_ClickCheckMoreBtn:(UIButton *)sender{

    self.block(@"");
    [self.cellTableView reloadData];
}


@end



#pragma mark 🔥 LSAnalyzeRankCell
@interface LSAnalyzeRankCell()


@property (nonatomic, strong) NSMutableArray * labelArray;

@end

@implementation LSAnalyzeRankCell

- (NSMutableArray *)labelArray{
    if (!_labelArray) {
        _labelArray = @[].mutableCopy;
    }
    return _labelArray;
}

+(LSAnalyzeRankCell *)AnalyzeRankCellByTableView:(UITableView *)tableView{
    LSAnalyzeRankCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSAnalyzeRankCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    
    return self;
}

-(void)addContentView{
    NSArray *titleArray = @[@"16",@"莫斯科火车头",@"12",@"3/6/4",@"12/16",@"-2",@"15"];
    CGFloat width=(LSScreenWidth - 20)/7;
    UILabel *lable;
    for (int i=0; i<7; i++) {
        lable=[UILabel new];
        lable.text = titleArray[i];
        lable.textColor = LSTitleGrayColor3;
        lable.font=LSFontSize(12, LSScreenWidth);
        lable.textAlignment = NSTextAlignmentCenter;
        lable.tag=i;
        lable.numberOfLines = 2;
        [self.contentView addSubview:lable];
        [self.labelArray addObject:lable];
        lable.sd_layout.leftEqualToView(self.contentView).offset(width*i + 10).topEqualToView(self.contentView).centerYEqualToView(self.contentView).widthIs(width).heightIs(30);

    }
}

- (void)setModel:(IntegralRankList *)model{
    _model = model;
    NSArray * array = @[model.Ranking,model.TeamName,model.AllGame,[NSString stringWithFormat:@"%@/%@/%@",model.WinGame,model.FlatGame,model.LostGame],[NSString stringWithFormat:@"%@/%@",model.WinScore,model.LostScore],model.NetScore,model.AllScore];
    [self.labelArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UILabel * label = (UILabel *)obj;
        label.text = array[idx];
    }];
    
}

@end


#pragma mark 🔥 LSAnalyzeDataCell
@interface LSAnalyzeDataCell()


@property (nonatomic, strong) NSMutableArray * labelArray;

@end

@implementation LSAnalyzeDataCell


- (NSMutableArray *)labelArray{
    if (!_labelArray) {
        _labelArray = @[].mutableCopy;
    }
    
    return _labelArray;
}
+(LSAnalyzeDataCell *)AnalyzeDataCellByTableView:(UITableView *)tableView{
    LSAnalyzeDataCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSAnalyzeDataCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    
    return self;
}

-(void)addContentView{
    NSArray *titleArray = @[@"莫斯科火车头",@"16",@"2.2",@"4",@"0.8",@"60.0%",@"40.0%",@"0.0%"];
    CGFloat width=(LSScreenWidth - 20)/8;
    UILabel *lable;
    for (int i=0; i<titleArray.count; i++) {
        lable=[UILabel new];
        lable.text = titleArray[i];
        lable.textColor = LSTitleGrayColor3;
        lable.numberOfLines = 2;
        lable.font=LSFontSize(12, LSScreenWidth);
        lable.textAlignment = NSTextAlignmentCenter;
        lable.tag=i;
        [self.contentView addSubview:lable];
        [self.labelArray addObject:lable];
        lable.sd_layout.leftEqualToView(self.contentView).offset(width*i + 10).topEqualToView(self.contentView).centerYEqualToView(self.contentView).widthIs(width).heightIs(30);
        
    }
}
- (void)setModel:(AnalysisDataComparisonList *)model{
    _model = model;
    
//    NSString * win = [model.AllWin componentsSeparatedByString:@" "].firstObject;
//    NSString * flat = [model.AllFlat componentsSeparatedByString:@" "].firstObject;
    
    NSArray * array = @[model.TeamName,model.AllGoal,model.AllAverageGoal,model.AllFumble,model.AllAverageFumble,model.AllWin,model.AllFlat,model.AllLost];
    [self.labelArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UILabel * label = (UILabel *)obj;
        label.text = array[idx];
    }];
    
    
}

@end


#pragma mark 🔥 LSAnalyzeRecommendCell
@interface LSAnalyzeRecommendCell()




@end

@implementation LSAnalyzeRecommendCell

+(LSAnalyzeRecommendCell *)AnalyzeRecommendCellByTableView:(UITableView *)tableView{
    LSAnalyzeRecommendCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSAnalyzeRecommendCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    
    return self;
}

-(void)addContentView{
    
    
    UILabel *contentLable = [[UILabel alloc] init];
//    contentLable.backgroundColor = [UIColor blueColor];
    
    contentLable.numberOfLines = 2;
    contentLable.font = LSFontSize13;
    contentLable.textColor = LSTitleGrayColor3;
    contentLable.text = @"    莫斯科火车头信心指数（88.8%），近三场变心啊欠佳。克拉斯诺达由于近三场连败，加上上场比赛中前锋受伤，固本场比赛不会出战出站出站";
    [self.contentView addSubview:contentLable];
    contentLable.sd_layout.leftEqualToView(self.contentView).offset(10).topEqualToView(self.contentView).rightEqualToView(self.contentView).offset(-10).bottomEqualToView(self.contentView);
    
    
    UIView *redDotImageView = [[UIView alloc] init];
    redDotImageView.layer.masksToBounds = YES;
    redDotImageView.layer.cornerRadius = 2.5f;
    [contentLable addSubview:redDotImageView];
    redDotImageView.backgroundColor = LSSubColorFF9E44;
    redDotImageView.sd_layout.leftEqualToView(contentLable).offset(5).topEqualToView(self.contentView).offset(18).widthIs(5).heightIs(5);
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
